package com.example.demo.common;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-01-07
 * Time: 12:34
 */
public class AjaxResult {

    /**
     * 业务执行成功时统一返回数据
     * @param data
     * @return
     */
    public static HashMap<String, Object> success(Object data){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code",200);
        hashMap.put("msg", "");
        hashMap.put("data",data);
        return hashMap;
    }

    public static HashMap<String, Object> success(String msg,Object data){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code",200);
        hashMap.put("msg", msg);
        hashMap.put("data",data);
        return hashMap;
    }

    /**
     * 业务执行失败时统一返回数据
     * @param
     * @return
     */
    public static HashMap<String, Object> fail(Integer code,String msg){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code",code);
        hashMap.put("msg", msg);
        return hashMap;
    }

    public static HashMap<String, Object> fail(Integer code,String msg,Object data){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code",code);
        hashMap.put("msg", msg);
        hashMap.put("data",data);
        return hashMap;
    }
}
